{extend name="base" /}
{block name="body"}
<link rel="stylesheet" href="/static/dist/basic.min.css" />
<link rel="stylesheet" href="/static/dist/dropzone.min.css" />

<div class="layui-card" style="width: 1000px;height: 1600px">
    <div class="layui-card-body">
        <form action="{:request()->url()}" class="layui-form" method="post">
            <div class="layui-form-item">
                <label class="layui-form-label">保险公司名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" value="{$data.name|default=''}" autocomplete="off" placeholder="请输入公司名称" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">公司图标</label>
                <div class="layui-input-block">
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="test-upload-normal-img" src="{$data.path|default=''}" width="400" height="200">
                    </div>
                    <input type="hidden" name="path" value="{$data.path|default=''}" autocomplete="off" placeholder="" class="layui-input">
                    <button type="button" class="layui-btn ajax-avatar"><i class="fa fa-file-image-o"></i> 选择图片</button>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">选择机构</label>
                <div class="layui-input-block">
                    <select name="aid" lay-verify="required">
                        {if condition="!empty($aid)"}
                        <option value="{$aid}">{$aname}</option>
                        {else}
                        {volist name='agency' id='vo'}
                        <option value="{$vo.id}">{$vo.name}</option>
                        {/volist}
                        {/if}
                    </select>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea name="memo" placeholder="请输入内容" class="layui-textarea">{$data.memo|default=''}</textarea>
                </div>
            </div>

            <input name="isedit" value="{:input('isedit')}" hidden="hidden">


            {if condition="input('isedit') == 1"}
            <input value="{$data.id}" hidden="hidden" name="id">
            {/if}
        </form>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-filter="i" id="sub" >保存</button>
            </div>
        </div>

    </div>
</div>

<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script src="/static/js/clipboard.js"></script>
<script src="/static/dist/dropzone.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery.serializeJSON/2.6.2/jquery.serializejson.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.all.js"> </script >

{/block}

{block name="js"}
<script>
    $('#sub').click(function(){
        if($('input[name="name"]').val() == ''){
            layer.open({
                content: '保险公司名称必填' //这里content是一个普通的String
            });
            return;
        }

        if($('input[name="aid"]').val() == ''){
            layer.open({
                content: '机构必选' //这里content是一个普通的String
            });
            return;
        }

        var data = $('form').serializeJson();
        $.ajax({
            url:'company_add',
            data: data,
            method:'post',
            success:function(res){
                layer.open({
                    content: res.msg, //这里content是一个普通的String
                    end: function(){ //此处用于演示
                        if(res.code == 1){
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.location.reload();//刷新父页面，注意一定要在关闭当前iframe层之前执行刷新
                            parent.layer.close(index); //再执行关闭
                        }
                    }
                });


            }
        });

        //$('form').submit();
    })
</script>
{/block}
